package iscript.gameFramework.GameLite 
{
	import com.greensock.loading.LoaderMax;
	import flash.display.Stage;
	import flash.system.ApplicationDomain;
	import flash.system.Capabilities;
	import flash.system.LoaderContext;
	import flash.utils.getDefinitionByName;
	import iscript.gameFramework.GameLite.content.GameContent;
	import iscript.gameFramework.GameLite.core.GameTimeUpdate;
	import iscript.gameFramework.GameLite.data.GameDataService;
	import iscript.gameFramework.GameLite.directEvent.IDirectEventManager;
	import iscript.gameFramework.GameLite.graphics.GraphicsDeviceManager;
	import iscript.gameFramework.GameLite.input.KeyInput;
	import iscript.gameFramework.GameLite.input.MouseInput;
	import iscript.gameFramework.GameLite.directEvent.DirectEventManager;
	import iscript.gameFramework.GameLite.system.GameHack;
	import iscript.gameFramework.NetService.ServiceProxy;
//	import iscript.gameFramework.GameLite.system.globalization.CultureInfo;
	
	public class Game 
	{
		static private var _initialized:Boolean;
		static private var _gameContent:GameContent;
		static private var _graphicsDeviceManager:GraphicsDeviceManager;
		//static private var _cultureInfo:CultureInfo;
		static private var _mouseInput:MouseInput;
		static private var _gamehack:GameHack;
		static private var _gametimeUpdate:GameTimeUpdate;
		static private var _gameDirectEventManager:IDirectEventManager;
		static private var _keyInput:KeyInput;
		static private var _gameDataService:GameDataService;
		static private var _IsDebugMode:Boolean;
		
		
		public function Game(stage:Stage) 
		{
			if (_initialized) throw new Error(" Game FrameWork is Initialized ");
			_gamehack = new GameHack();
			_gamehack.keepframe();
			_graphicsDeviceManager = new GraphicsDeviceManager(stage);
			LoaderMax.defaultContext = new LoaderContext(false, currentApplicationDomain);
			//Game TimeUpdate
			_gametimeUpdate = new GameTimeUpdate();
			_gameContent = new GameContent();
			//_cultureInfo = new CultureInfo();
			_mouseInput = new MouseInput();

			//var c:Class = getDefinitionByName("iscript.gameFramework.GameLite.directEvent.DirectEventManager") as Class;
			//_gameDirectEventManager =IDirectEventManager( new getDefinitionByName("iscript.gameFramework.GameLite.directEvent.DirectEventManager") );
			_gameDirectEventManager = new DirectEventManager();
			
			
			_keyInput = new KeyInput();			
			_gameDataService = new GameDataService();
			_IsDebugMode = true;
			_initialized = true;
		}
		
		
		
		static public function get INITIALIZED():Boolean{return _initialized}		
		static public function get Content():GameContent { return _gameContent; }		 
		static public function get currentApplicationDomain():ApplicationDomain {
			  if (INITIALIZED) return  _graphicsDeviceManager.stage.loaderInfo.applicationDomain;
			  return ApplicationDomain.currentDomain;
			}	
		static public function get graphicsDeviceManager():GraphicsDeviceManager { return _graphicsDeviceManager; }
		
		static public function get DataService():GameDataService { return _gameDataService;}
		
		static public function get Hack():GameHack { return _gamehack; }
		static public function get DirectEvent():IDirectEventManager { return _gameDirectEventManager; }
		static public function get Service():ServiceProxy { return ServiceProxy.instance; }
		
		static public function get TimeUpdate():GameTimeUpdate { return  _gametimeUpdate; }
 
		//static public function get cultureInfo():CultureInfo { return _cultureInfo }		
		static public function get mouseInput():MouseInput { return _mouseInput; }		
		static public function get keyInput():KeyInput { return _keyInput; }
		
		static public function get IsDebugMode():Boolean 
		{
			return false;
			return  Capabilities.isDebugger;
		}
		
		//public function set cultureInfo():CultureInfo { return _cultureInfo }		
		   
	/*	public function initialize(cultureInfo:CultureInfo):void {
			_cultureInfo = cultureInfo;
			}*/
	}
}
